package com.haha.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class RadioButtonActivity extends AppCompatActivity {

    private RadioGroup rg_1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_button);
        rg_1= (RadioGroup)findViewById(R.id.rg_1);
        //当check效果变化的时候
        rg_1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            //这里的参数i，表示的是选中的radiobutton的id号
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton =(RadioButton) findViewById(i);
                Toast.makeText(RadioButtonActivity.this,"当前选中的是："+radioButton.getText(),Toast.LENGTH_SHORT).show();
            }
        });
    }
}